package org.frog.sgs.develop;

import java.io.FileInputStream;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 * @author duanxiangqi
 * @date 2012-10-30
 */
public class LoadSgsEventCodes {

	public static final String path = "D:/MyEclipseWorkspace/sgs-frog-simple-test/develop/msg.xls";

	public static void main(String[] args) throws Exception {
		HSSFWorkbook book = new HSSFWorkbook(new FileInputStream(path));
		HSSFSheet sheet = book.getSheetAt(2);
		int lastRowNum = sheet.getLastRowNum();
		for (int i = 1; i <= lastRowNum; i++) {
			HSSFRow row = sheet.getRow(i);
			if (row.getCell((short) 0) == null) {
				continue;
			}
			String desc = row.getCell((short) 0).getStringCellValue();
			if (StringUtils.isBlank(desc)) {
				continue;
			}
			String name = row.getCell((short) 1).getStringCellValue();
			int num = (int) row.getCell((short) 2).getNumericCellValue();
			System.out.print("/**" + desc + "*/int " + name + "=" + num + ";\t");
			String methodName = "";
			char[] cs = name.toLowerCase().toCharArray();
			boolean toUpper = false;
			for (int j = 0; j < cs.length; j++) {
				if ('_' == cs[j]) {
					toUpper = true;
				} else if (toUpper) {
					toUpper = false;
					methodName += Character.toUpperCase(cs[j]);
				} else {
					methodName += cs[j];
				}
			}
			System.out.print("addListener(SgsEventCode." + name + ", BaseEventListener.class, \"" + methodName
					+ "\");\t");
			System.out.print("/**" + desc + "*/void " + methodName + "(SgsMsg msg);\t");
			System.out.print("/**" + desc + "*/public void " + methodName + "(SgsMsg msg){}");
			System.out.println();
		}
	}
}
